package com.xpgk.mvc.bentryRegister;

import java.util.List;

import com.jfinal.log.Log;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
/**
 * 顾客产品信息model
 */
@SuppressWarnings("unused")
@Table(tableName = CustomerProduct.table_name)
public class CustomerProduct extends  BaseModel<CustomerProduct>{
	private static final long serialVersionUID = 6761767368352810428L;

	private static final Log log = Log.getLog(CustomerProduct.class);

	public static final CustomerProduct dao = new CustomerProduct().dao();
	
	
	/**
	 * 表名称
	 */
	public static final String table_name = "sb_customer_product";
	
	/**
	 * 字段描述：ids 字段类型：character varying 长度：11
	 */
	public static final String column_ids = "ids";
	/**
	 * 字段描述：机构id 字段类型：character varying 长度：32
	 */
	public static final String column_organids= "organids";
	/**
	 * 字段描述：customerID 字段类型：character varying 长度：11
	 */
	public static final String column_customerID = "customerID";

	/**
	 * 字段描述：产品ID 字段类型：character varying 长度：11
	 */
	public static final String column_productID = "productID";

	/**
	 * 字段描述：产品数量 字段类型：bigint  长度：11
	 */
	public static final String column_count = "count";
	
	
	public static final String column_yxDate = "yxDate";

	/**
	 * 字段描述：产品规格 字段类型：float 长度：11
	 */
	public static final String column_capacity = "capacity";
	/**
	 * 字段描述：购买产品时单价 字段类型：float 长度：11
	 */
	public static final String column_proUnitPrice = "proUnitPrice";

	/**
	 * 字段描述：购买产品时单价 字段类型：float 长度：11
	 */
	public static final String column_productNo = "productNo";
	
	/**
	 * 字段描述：产品剩余总克数    字段类型：float 长度：11
	 */
	public static final String column_capacities = "capacities";
	/**
	 * 字段描述：产品经验值    字段类型：float 长度：11
	 */
	public static final String column_proExperience = "proExperience";
	/**
	 * 字段描述：产品剩余总经验值   字段类型：float 长度：11
	 */
	public static final String column_totalExperience = "totalExperience";
	public static final String column_dataStatus = "dataStatus";
	/**
	 * 字段描述：状态
	 */
	public static final String column_status = "status";


	/**
	 * 字段描述：该条数据添加人员is  字段类型：character varying 长度：32
	 */
	public static final String column_createId = "createId";
	/**
	 * 字段描述：该条数据添加时间  字段类型：datetime 长度：0
	 */
	public static final String column_createDate = "createDate";
	/**
	 * 字段描述：该条数据更新人员id  字段类型：character varying 长度：100
	 */
	public static final String column_updateId = "updateId";
	/**
	 * 字段描述：该条数据更新时间  字段类型：datetime 长度：0
	 */
	public static final String column_updateDate = "updateDate";
	/**
	 * sqlId :sb.customerProduct.column
	 * 描述：查询顾客信息，自定义字段
	 */
	public static final String sqlId_column= "sb.customerProduct.column";
	/**
	 * sqlId :sb.customerProduct.selByCusAndPro
	 * 描述：根据顾客和产品查询
	 */
	public static final String sqlId_selByCusAndPro= "sb.customerProduct.selByCusAndPro";
	/**
	 * sqlId :sb.customerProduct.selByCusAndOrg
	 * 描述：根据顾客和机构查询
	 */
	public static final String sqlId_selByCusAndOrg= "sb.customerProduct.selByCusAndOrg";
	/**
	 * sqlId :sb.customerProduct.selByCusAndType
	 * 描述：根据顾客和类别查询
	 */
	public static final String sqlId_selByCusAndType= "sb.customerProduct.selByCusAndType";
	/**
	 * sqlId :sb.customerProduct.selByCusAndUseIds
	 * 描述：根据顾客和产品用途查询
	 */
	public static final String sqlId_selByCusAndUseIds= "sb.customerProduct.selByCusAndUseIds";
	
	/**
	 * sqlId :sb.customerProduct.selByCusAndUseIdsAndPartIds
	 * 描述：根据顾客和产品用途和服务部位查询
	 */
	public static final String sqlId_selByCusAndUseIdsAndPartIds= "sb.customerProduct.selByCusAndUseIdsAndPartIds";
	
	/**
	 * sqlId :sb.customerProduct.sqlId_selByCusIds
	 * 描述：根据顾客id查询
	 */
	public static final String sqlId_selByCusIds= "sb.customerProduct.selByCusIds";
	
	
	/**根据顾客和机构查询顾客产品
	 * 
	 * @return
	 */
	public List<CustomerProduct>  getCustomerProduct(String customerIds,String organIds)
	{
		String sql="SELECT  *  from  sb_customer_product  WHERE  customerID=?  and organids=? AND  `status`='1'";
		return  CustomerProduct.dao.find(sql,customerIds,organIds);
	}
	
	/**
	 *  根据机构，产品，剩余次数查出所有顾客 
	 */
	public List<CustomerProduct>  getCusProByope(String organIds,String productIds,String experience)
	{
		String sql="SELECT * FROM sb_customer_product scp LEFT JOIN sb_customer sc ON sc.ids = scp.customerID"+
				  " AND sc.organIds = scp.organids WHERE sc.organIds = ? and scp.productID = ?  and scp.totalExperience < ? and scp.`status`='1'";
		return  CustomerProduct.dao.find(sql,organIds,productIds,experience);
	}
}
